import {createRouter, createWebHistory} from "vue-router";
//会将所有js混在一起
/*
import Home from "../views/Home";
import User from "../views/User";
import About from "../views/About";
*/
//懒加载，一个组件一个JS
const Home = () => import("../views/Home");
const About = () => import("../views/About");
const User = () => import("../views/User");
const MyOrder = () => import("../views/MyOrder");
const MySetting = () => import("../views/MySetting");
const MyPage = () => import("../views/MyPage")
const MyArticle = () => import("../views/MyArticle")

const routes = [
    {
        path: '/',
        name: 'HomeRoot',
        component: Home,
        meta: {title: "111"}
    },
    {
        path: '/home',
        name: 'Home',
        // redirect: '/',
        redirect: {name: 'HomeRoot'},
        component: Home
    },
    {
        path: '/about',
        name: 'About',
        alias: ['/a', '/b', '/c'],
        // lazy-load , js单独打包， 加快了页面速度
        // component: () => import('../views/About'),
        component: About
    },
    {
        path: '/user',
        component: User,
        children: [
            {
                path: '',
                component: MyOrder
            },
            {
                path: 'order',
                component: MyOrder
            },
            {
                path: 'setting',
                component: MySetting
            },
            {
                path: 'page/:id',
                // redirect: to => {
                //     return {path: 'article', query: {name: 'z3', age: to.params.id}}
                // },
                alias: ['p/:id', 'x/:id'],
                component: MyPage
            },
            {
                path: 'article',
                component: MyArticle
            },
        ]
    }
]

const router = createRouter({
    history: createWebHistory(process.env.BASE_URL),
    routes
});

router.beforeEach((to, from) => {
    document.title = to.meta.title;
});

router.afterEach((to, from) => {

});

export default router
